function com_dataset_dataset_tempstored() {
    //http://taffydb.com/
    this.tempStored = new TAFFY();
    this.expiredays = 1;
}

com_dataset_dataset_tempstored.prototype = {
    SQL_DATA_TYPE: {
        FIELD: "field",
        FILTER: "filter",
        ORDER: "order",
        ORDER_REL: "order_rel",
        SCREEN: "screen"
    },
    STORED_PROPERTY: {
        Type: "type",
        Time: "time",
        Context: "cxt"
    },
    STORAGE_MODE: {
        TAFFY: "taffy", //刷新页面就消失
        COOKIE: "cookie",//关闭浏览器仍然有效，大小受限4k
        LOCALSTORAGE: "localstorage", //关闭浏览器仍然有效，大小>4k
        SESSIONSTORAGE: "sessionstorage"
        //其它存储方式：
        //2.本地存储sessionstorage
        //3.离线缓存（application cache）
        //4.Web SQL
        //5.IndexedDB
    },
    TAB_TYPE: {
        FIELD: "field",
        FILTER: "filter",
        ORDER_DEFINE: "orderDefine",
        ORDER_REL: "orderRel"
    },
    _isJsonObject_: function (obj) {
        if (typeof(obj) == "object"
            && Object.prototype.toString.call(obj).toLowerCase() == "[object object]"
            && !obj.length) {
            return true;
        }
        return false;
    },
    stored: function (type, json, storage_mode) {
        if (this.SQL_DATA_TYPE.propertyIsEnumerable(type)) {
            throw 'the param [type] is not a enum item of SQL_DATA_TYPE.';
        }

        if (this._isJsonObject_(json)) {
            throw 'the param [json] is not a json object.';
        }

        if (this.STORAGE_MODE.propertyIsEnumerable(storage_mode)) {
            throw 'the param [storage_mode] is not a enum item of STORAGE_MODE.';
        }

        if (this.STORAGE_MODE.TAFFY == storage_mode) {
            this.tempStored(type).remove();
            this.tempStored.insert(json);
            return;
        }

        if (this.STORAGE_MODE.COOKIE == storage_mode) {
            this._removeCookie_(type);
            $.cookie(type, json, {expires: this.expiredays});
        }

        if (this.STORAGE_MODE.SESSIONSTORAGE == storage_mode) {
            if (!window.sessionStorage) {
                throw 'This browser does NOT support sessionStorage.';
            }
            sessionStorage.setItem(type, JSON.stringify(json));
            return;
        }

        if (!window.localStorage) {
            throw 'This browser does NOT support localStorage.';
        }
        // if (window.localStorage.getItem(type).isNotEmpty()) {
        //     localStorage.removeItem(type);
        // }
        window.localStorage.setItem(type, JSON.stringify(json));
    },
    getStored: function (searchJSON, storage_mode) {
        if (!this._isJsonObject_(searchJSON)) {
            throw 'the param [searchJSON] is not a json object.';
        }
        var result = [];
        if (this.STORAGE_MODE.TAFFY == storage_mode) {
            this.tempStored(searchJSON).each(function (r) {
                result.push(r);
            });
            return result;
        }
        if (this.STORAGE_MODE.COOKIE == storage_mode) {
            result.push($.cookie(searchJSON[this.STORED_PROPERTY.Type]));
            return result;
        }

        if (this.STORAGE_MODE.SESSIONSTORAGE == storage_mode) {
            if (!window.sessionStorage) {
                throw 'This browser does NOT support sessionStorage.';
            }

            return JSON.parse(window.sessionStorage.getItem(searchJSON[this.STORED_PROPERTY.Type]));
        }

        if (!window.localStorage) {
            throw 'This browser does NOT support localStorage.';
        }
        return JSON.parse(window.localStorage.getItem(searchJSON[this.STORED_PROPERTY.Type]));
    },
    removeStored: function (type, storage_mode) {
        if (this.SQL_DATA_TYPE.propertyIsEnumerable(type)) {
            throw 'the param [type] is not a enum item of SQL_DATA_TYPE.';
        }

        if (this.STORAGE_MODE.COOKIE == storage_mode) {
            var val = $.cookie(type);
            if (val != null && val != [] && val != {}) {
                $.cookie(type, '', {expires: -1});
            }
            return;
        }

        if (this.STORAGE_MODE.SESSIONSTORAGE == storage_mode) {
            if (!window.sessionStorage) {
                throw 'This browser does NOT support sessionStorage.';
            }
            var val = sessionStorage.getItem(type);
            // console.log("val==>" + val);
            if (val != null) {
                sessionStorage.removeItem(type);
            }
            return;
        }
    }
}
